package sust.cse.ruhul.jpbs1.util;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.util.Log;

public class FileUtil
{
	public static final String TAG = FileUtil.class.getSimpleName();
	public static Uri cameraFileUri;
	private static File cameraDirectory;
	
	static
	{
		final String state = Environment.getExternalStorageState();
		if (Environment.MEDIA_MOUNTED.equals(state))
		{
			if (!Environment.MEDIA_MOUNTED_READ_ONLY.equals(state))
			{
				// Older devices (for instance a Samsung phone with Android 2.3) may
				// not have the "DIRECTORY_PICTURES" directory.
				// Therefore we will use the traditional DCIM directory:
				final File dcim = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
				if (dcim.exists())
				{
					cameraDirectory = dcim;
				}
				else
				{
					Log.d(TAG, "ExternalStorageState DCIM directory does not exist (SDK " + Build.VERSION.SDK_INT + ")");
				}
			}
			else
			{
				Log.d(TAG, "ExternalStorageState is read-only (SDK " + Build.VERSION.SDK_INT + ")");
			}
		}
		else
		{
			Log.d(TAG, "ExternalStorageState is not mounted (SDK " + Build.VERSION.SDK_INT + ")");
		}
	}

	public static final File createEmptyCameraFile()
	{
		if (cameraDirectory != null)
		{
			final SimpleDateFormat dateFormat = new SimpleDateFormat("'IMG_'yyyyMMdd'_'HHmmss'.jpg'");
			final String filename = dateFormat.format(new Date());
			return new File(cameraDirectory, filename);
		}else{
			final SimpleDateFormat dateFormat = new SimpleDateFormat("'IMG_'yyyyMMdd'_'HHmmss'.jpg'");
			final String filename = dateFormat.format(new Date());
			cameraDirectory = Environment.getExternalStorageDirectory();
			return new File(cameraDirectory, filename);			
		}
	}

}
